package com.hup.minicontroller.client.view.connected;

import com.hup.minicontroller.client.model.AppState;
import com.hup.minicontroller.common.model.dto.ControlConfigDto;
import com.hup.utils.swing.customView.SeekBarView;

import javax.swing.*;
import java.awt.*;

/**
 * @author hugan
 * @date 2021/5/24
 */
public class ControlConfigPanel extends JPanel {
    public JPanel root;

    public JLabel txtServerInfo;
    public JLabel txtNetSpeed;
    public JCheckBox cbEnableScreen;
    public SeekBarView<Integer> sbFps;
    public SeekBarView<Integer> sbScreenSize;
    public SeekBarView<Integer> sbScreenQuality;
    public JCheckBox btnDrawFull;

    public ControlConfigPanel() {
        $$$setupUI$$$();
    }

    private void createUIComponents() {
        root = this;
    }

    /**
     * Method generated by IntelliJ IDEA GUI Designer
     * >>> IMPORTANT!! <<<
     * DO NOT edit this method OR call it in your code!
     *
     * @noinspection ALL
     */
    private void $$$setupUI$$$() {
        createUIComponents();
        root.setLayout(new GridBagLayout());
        root.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black), null));
        txtServerInfo = new JLabel();
        txtServerInfo.setText("已连接:xxx");
        GridBagConstraints gbc;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.gridwidth = 2;
        gbc.anchor = GridBagConstraints.WEST;
        root.add(txtServerInfo, gbc);
        txtNetSpeed = new JLabel();
        txtNetSpeed.setText("网速:");
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.gridwidth = 2;
        gbc.anchor = GridBagConstraints.WEST;
        root.add(txtNetSpeed, gbc);
        cbEnableScreen = new JCheckBox();
        cbEnableScreen.setHorizontalTextPosition(2);
        cbEnableScreen.setText("传输图像");
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 2;
        gbc.weightx = 1.0;
        gbc.anchor = GridBagConstraints.WEST;
        root.add(cbEnableScreen, gbc);
        sbFps = new SeekBarView();
        sbFps.setLabel("帧率:");
        sbFps.setUnit("fps");
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 3;
        gbc.gridwidth = 2;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        root.add(sbFps, gbc);
        sbScreenSize = new SeekBarView();
        sbScreenSize.setLabel("图像大小:");
        sbScreenSize.setUnit("px");
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 4;
        gbc.gridwidth = 2;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        root.add(sbScreenSize, gbc);
        sbScreenQuality = new SeekBarView();
        sbScreenQuality.setLabel("图像质量:");
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 5;
        gbc.gridwidth = 2;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        root.add(sbScreenQuality, gbc);
        btnDrawFull = new JCheckBox();
        btnDrawFull.setHorizontalTextPosition(2);
        btnDrawFull.setText("平铺图像");
        gbc = new GridBagConstraints();
        gbc.gridx = 1;
        gbc.gridy = 2;
        gbc.weightx = 1.0;
        gbc.anchor = GridBagConstraints.WEST;
        root.add(btnDrawFull, gbc);
    }

    /**
     * @noinspection ALL
     */
    public JComponent $$$getRootComponent$$$() { return root; }

    public void updateState(ControlConfigDto controlConfig, AppState appState) {
        cbEnableScreen.setSelected(controlConfig.isEnableScreen());
        sbFps.setVisible(controlConfig.isEnableScreen());
        sbScreenSize.setVisible(controlConfig.isEnableScreen());
        sbScreenQuality.setVisible(controlConfig.isEnableScreen());
        btnDrawFull.setVisible(controlConfig.isEnableScreen());
        if (controlConfig.isEnableScreen()) {
            sbFps.setValue(controlConfig.getFps());
            sbScreenSize.setValue(controlConfig.getScreenSize());
            sbScreenQuality.setValue(controlConfig.getScreenQuality());
            btnDrawFull.setSelected(appState.getAppConfig().isDrawFull());
        }
    }
    
}
